package cn.wubo.multi.thread.demo01;

import java.util.Timer;
import java.util.TimerTask;
import java.util.stream.IntStream;

/**
 * TimerTask 定时任务
 */
public class Demo0103 {

    public static void main(String[] args) {
        IntStream.range(0, 10).forEach(i -> {
            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    //等待一会
                    try {
                        Thread.sleep((int) (Math.random() * 100));
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName());
                }
            }, 0);
        });
    }
}
